import { IsOptional, IsString, IsEnum, MaxLength } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'

/**
 * 文件类型枚举
 */
export enum FileType {
  IMAGE = 'image',
  DOCUMENT = 'document',
  VIDEO = 'video',
  AUDIO = 'audio',
  OTHER = 'other'
}

/**
 * 文件上传DTO
 */
export class UploadDto {
  @ApiProperty({
    description: '文件类型',
    enum: FileType,
    example: FileType.IMAGE,
    required: false
  })
  @IsOptional()
  @IsEnum(FileType, { message: '文件类型无效' })
  type?: FileType

  @ApiProperty({
    description: '文件描述',
    example: '用户头像',
    required: false,
    maxLength: 255
  })
  @IsOptional()
  @IsString({ message: '文件描述必须是字符串' })
  @MaxLength(255, { message: '文件描述最多255个字符' })
  description?: string

  @ApiProperty({
    description: '文件标签',
    example: 'avatar,profile',
    required: false
  })
  @IsOptional()
  @IsString({ message: '文件标签必须是字符串' })
  tags?: string
}

/**
 * 图片处理选项DTO
 */
export class ImageProcessDto {
  @ApiProperty({
    description: '图片宽度',
    example: 800,
    required: false
  })
  @IsOptional()
  width?: number

  @ApiProperty({
    description: '图片高度',
    example: 600,
    required: false
  })
  @IsOptional()
  height?: number

  @ApiProperty({
    description: '图片质量 (1-100)',
    example: 80,
    required: false
  })
  @IsOptional()
  quality?: number

  @ApiProperty({
    description: '输出格式',
    example: 'webp',
    enum: ['jpeg', 'png', 'webp', 'avif'],
    required: false
  })
  @IsOptional()
  @IsEnum(['jpeg', 'png', 'webp', 'avif'], { message: '不支持的图片格式' })
  format?: 'jpeg' | 'png' | 'webp' | 'avif'
}
